import 'package:flutter/material.dart';
import 'package:wheel_of_fortune/model/candy_record_model.dart';
import 'package:wheel_of_fortune/utils/utils.dart';

class ItemWidget extends StatelessWidget {
  final type;
  final CandyRecordModel item;
  const ItemWidget({this.type = 0, this.item, Key key}) : super(key: key);

  getTitle(type) {
    if (type == 'ROTARY_TABLE_PRIZE') {
      return 'Earned Candy';
    } else if (type == 'ROTARY_TABLE_LOTTERY_EXCHANGE') {
      return 'Exchanged Candy';
    }
    return '';
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.fromLTRB(30, 20, 20, 25),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Expanded(child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                getTitle(this.item.type),
                style: TextStyle(
                    color: black3AColor,
                    fontSize: 12,
                    fontFamily: 'Avenir Next LT Pro'),
              ),
              SizedBox(height: 5),
              Text(
                'Transaction ID: ${this.item.id}',
                overflow: TextOverflow.ellipsis,
                style: TextStyle(
                    color: greyDBColor,
                    fontSize: 7,
                    fontFamily: 'Avenir Next LT Pro'),
              ),
            ],
          )),
          SizedBox(height: 3,),
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                '${this.item.amount > 0 ? '+' : '-'} ${this.item.amount>0?this.item.amount.toInt():-this.item.amount.toInt()} Candies',
                style: TextStyle(
                    color: this.item.amount > 0 ? Colors.green : Colors.red,
                    fontSize: 12,
                    fontFamily: 'Avenir Next LT Pro'),
              ),
              SizedBox(height: 5),
              Text(
                DateTimeHelper.getDate(this.item.createdTime),
                // '21 May 2020 5:04 PM',
                style: TextStyle(
                    color: greyDBColor,
                    fontSize: 7,
                    fontFamily: 'Avenir Next LT Pro',),
              ),
            ],
          ),
        ],
      ),
    );
  }
}
